// 登录界面处理
import global from "./../global";

cc.Class({
    extends: cc.Component,

    properties: {
        createrPlayerNode: cc.Node,
    },

    onLoad () {
        global.Socket.init();

        global.Socket.onLogin((data)=>{
            if (data.createrplayer == 'ok') {
                this.createrPlayerNode.active = true;
                global.AdministrationData.PlayerData.GameID = data.gameID;
                global.AdministrationData.PlayerData.avatarUrl = data.avatarUrl;
            }
        });
    },

    onLognButton: function(event, sign) {
        switch(sign) {
            case 'lognBtn': {           // 登录按钮
                global.Socket.login(
                    global.AdministrationData.PlayerData.account,
                    global.AdministrationData.PlayerData.password,
                    global.AdministrationData.PlayerData.uniqueID,
                    global.AdministrationData.PlayerData.nickName,
                    global.AdministrationData.PlayerData.avatarUrl, null);
                break;
            }
            case 'createrPlayer': {     // 创建角色
                global.Socket.creatorPlayer(
                    global.AdministrationData.PlayerData.GameID,
                    1,
                    global.AdministrationData.PlayerData.nickName,
                    global.AdministrationData.PlayerData.avatarUrl, (err, data)=>{
                        cc.log('创建角色 = ' + JSON.stringify(data));
                        cc.director.loadScene('gameScene');
                    });
                break;
            }
            default:
                break;
        }
    }
});
